(function (a) {
    a.fn.slider = function (c) {
        var b = {
            height: 200,
            isShowMark: true,
            sliderDotSize: 16,
            barWidth: 6,
            step: 20
        };
        var e = a.extend(true, {}, b, c);

        function f(l, h, g, k) {
            var j = l / (e.height - e.sliderDotSize) * (g - h) + h;
            var newVal = parseInt(j);
            $(k).val(newVal);
            typeof e.change === "function" && e.change(newVal);
        }

        function d(k, p, j, l) {
            if (p - k < j) {
                return "<span>参数错误</span>"
            } else {
                var q = a('<div ondragstart="return false;" class="sliderWrap"></div>');
                q.height(e.height || 200);
                q[0].ismousedown = false;
                var h = a('<div class="sliderBar"></div>');
                var m = a('<span class="sliderDot"></span>');
                var line = a('<span class="sliderLine"></span>');
                m.css({
                    "height": e.sliderDotSize,
                    "height": e.sliderDotSize,
                    "top": -(e.sliderDotSize - e.barHeight) / 2
                });
                h.height(e.height);
                q.mousedown(function () {
                    this.ismousedown = true
                });
                q.on("click", function (t) {
                    if (!$(l).attr("enableInc")) {
                        return;
                    }
                    var s = a(this).children(".sliderBar").height() - (t.pageY - a(this).children(".sliderBar").offset().top + e.sliderDotSize / 2);
                    if (s < 0) {
                        s = 0
                    }
                    if (s > e.height - e.sliderDotSize) {
                        s = e.height - e.sliderDotSize
                    }
                    m.css("bottom", s);
                    line.css("height", s);
                    f(s, k, p, l)
                });
                q.on("mousemove", function (t) {
                    if (!$(l).attr("enableInc")) {
                        return;
                    }
                    if (this.ismousedown) {
                        var s = a(this).children(".sliderBar").height() - (t.pageY - a(this).children(".sliderBar").offset().top + e.sliderDotSize / 2);
                        if (s < 0) {
                            s = 0
                        }
                        if (s > e.height - e.sliderDotSize) {
                            s = e.height - e.sliderDotSize
                        }
                        m.css("bottom", s);
                        line.css("height", s);
                        f(s, k, p, l)
                    }
                });
                a(document).mouseup(function () {
                    q[0].ismousedown = false
                });
                q.append(h);
                h.append(m);
                h.append(line);
                // if ((p - k) % j !== 0) {
                //     e.isShowMark = false
                // }
                // if (e.isShowMark) {
                //     var o = '<div class="sliderMark">';
                //     var n = (p - k) / j;
                //     for (i = 0; i <= n; i++) {
                //         var r = e.height - e.sliderDotSize;
                //         var g = r / n * i + e.sliderDotSize / 2;
                //         splitValue = k + j * i;
                //         console.log("r", r, g);
                //         o += "<dl style='bottom:" + -g + "px'>" + "<dt></dt>" + "<dd>" + splitValue + "</dd>" + "</dl>"
                //     }
                //     o += "</div>";
                //     h.append(a(o))
                // }
                return q
            }
        }
        this.each(function () {
            var l = a(this);
            var h = parseInt(l.attr("min")) || 0;
            var g = parseInt(l.attr("max")) || 100;
            var j = parseInt(e.step);
            var k = d(h, g, j, this);
            var idxWrapper = a('<div class="axies-x">' + e.index + '</div>');
            a(k).insertAfter(l);
            a(idxWrapper).insertAfter(k);
            l.change(function () {
                var g = parseInt(l.attr("max")) || 100;
                if (this.value > g) {
                    this.value = g
                } else {
                    if (this.value < h) {
                        this.value = h
                    }
                }
                var m = this.value;
                var n = (m - h) / (g - h) * (e.height - e.sliderDotSize);
                k.find(".sliderDot").css("bottom", n)
                k.find(".sliderLine").css("height", n)
                typeof e.change === "function" && e.change(m);
            });
            if (this.value) {
                l.trigger("change")
            }
        });
        return this
    }
})(jQuery);